package sort;

/**
 * @author:李雄
 * @ClassName:DirectInsertionSort
 * @Description:直接插入排序
 * @createTime:2022-11-13 20:56
 */
public class DirectInsertionSort {
    public static void main(String[] args) {
        int arr[] = new int[]{3, 5, 9, 2, 0, 4};
        myDirectInsertionSort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    private static void myDirectInsertionSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j > 0; j--) {
                if (arr[j - 1] > arr[j]) {
                    int temp = arr[j];
                    arr[j] = arr[j - 1];
                    arr[j - 1] = temp;
                }
            }
        }
    }
}
